package com.auxgroup.smarthome;

import com.auxgroup.smarthome.utils.ProtocolConvertUtils;

/**
 * Created by kevinchen on 2017/9/8.
 * 家用空调和商用空调控制的公共方法 及其公共参数
 */
public class CommonControlFunction {

    public static final String HEAD = "BB00";

    public static final int HEAD1= 0xBB;

    public static final int HEAD2 = 0x00;

    public static final String CMD = "0680";

    public static final int CMD1= 0x06;

    public static final int CMD2 = 0x80;

    public static final String RET_CMD = "0000";

    public static final int RET_CMD1 = 0x00;

    public static final int RET_CMD2 = 0x00;
    /**
     * 表示app2dev的action
     */
    public static final int APP2_DEV_NUM = 0x05;

    /**
     * @param hexStrArr 样本原始数据：BB  00  07  00  00  00  04  00  01  01  BC  3D  7C  C0  这里的"7CCO"即为FCC校验码
     *                  new String[]{"BB00","0700","0000","0400","0101","BC3D"}
     *                                HEAD ， CMD ，RET_CMD ，BC ， DATA
     * @return 返回fcc校验码转成16进制字符串
     */
    public static String getFCC(String[] hexStrArr){
        int cksum = 0;
        for (int i = 0; i < hexStrArr.length; i++) {
            String str16 = ProtocolConvertUtils.highConvertLowHexStr(hexStrArr[i]);
            cksum += ProtocolConvertUtils.hexStrConvertDecimal(str16);
        }
        cksum = (cksum >> 16) + (cksum & 0xffff);
        cksum += (cksum >>16);
        cksum = ~cksum;
        String hexString = Integer.toHexString(cksum);
        String substringHexStr = ProtocolConvertUtils.substringHexStr(hexString, 4);
        return ProtocolConvertUtils.highConvertLowHexStr(substringHexStr);
    }


}
